import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';

@Component({
    selector: 'op-paginator',
    templateUrl: 'material-paginator.component.html',
    styleUrls: ['./material-paginator.component.scss', '../../../../../assets/styles/hide-element-focus-outline.css']
}

) export class MaterialPaginatorComponent implements OnInit {
    @Input() currentPage: number;
    @Input() length: number;
    @Input() pageLinkSize: number;
    @Input() pageSize: number;
    @Input() pageSizeOptions: number[];
    @Input() showFirstLastButtons: boolean;
    @Output() pageChanged: EventEmitter<any> = new EventEmitter<any>();

    constructor() { }

    ngOnInit(): void {
        this.initializeProperties();
    }

    onPageChanged(e: any) {
        this.pageChanged.emit({
            pageSize: e.pageSize,
            pageStartIndex: e.pageIndex * e.pageSize,
            pageEndIndex: (e.pageIndex * e.pageSize) + e.pageSize,
            totalPageCount: e.length,
            currentPage: e.pageIndex + 1
        }
        );
    }

    gotoPage(pageIndex: number): void { }

    protected initializeProperties(): void {
        this.pageSize = this.pageSize || 10;
        this.pageSizeOptions = this.pageSizeOptions || [10,
            20];
        this.showFirstLastButtons = this.showFirstLastButtons || true;
    }
}